package com.jd.platform.sample3.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.serializer.StringRedisSerializer;

/**
 * @author wuweifeng wrote on 2017/10/27.
 */
@Configuration
public class RedisConfig {

    @Bean(name = {"redisTemplate", "stringRedisTemplate"})
    public StringRedisTemplate stringRedisTemplate(RedisConnectionFactory factory) {
        StringRedisTemplate redisTemplate = new StringRedisTemplate();
        redisTemplate.setConnectionFactory(factory); //设置redis的连接工厂对象
        redisTemplate.setKeySerializer(new StringRedisSerializer()); //设置redis key的序列化器
//        redisTemplate.setValueSerializer(new StringRedisSerializer()); //设置redis value的序列化器
//        redisTemplate.afterPropertiesSet(); //初始化时的逻辑
        return redisTemplate;
    }

}
